<?php
	require_once "includes/class/member_management.class.php";
	require_once('AmazonAPI/.config.inc.php');
	require_once('AmazonAPI/CBUI/CBUIRecipientTokenPipeline.php');
	
	if($_SESSION['user_id_sess']=="") {
		echo "<script type='text/javascript'> window.location='index.php?signin&url=profile'; </script>";
	}
	
	if(isset($_REQUEST['signature']) && !empty($_REQUEST['signature'])) {
			// 12:46 PM Sunday, May, 29 2011
			$userId = $_SESSION['user_id_sess']; 
			$signature = $_REQUEST['signature'];
			$refundTokenID = $_REQUEST['refundTokenID'];
			$signatureVersion = $_REQUEST['signatureVersion'];
			$signatureMethod = $_REQUEST['signatureMethod'];
			$certificateUrl = $_REQUEST['certificateUrl'];
			$tokenID = $_REQUEST['tokenID'];
			$callerReference = $_REQUEST['callerReference'];
			$sqlUpdUsr = "UPDATE tbl_users SET comm_signature='".$signature."',
						comm_refundTokenID='".$refundTokenID."',
						comm_signatureVersion='".$signatureVersion."',
						comm_signatureMethod='".$signatureMethod."',					
						comm_certificateUrl='".$certificateUrl."',
						comm_tokenID='".$tokenID."',
						tokenID='".$tokenID."',
						comm_callerReference='".$callerReference."' WHERE user_id='$userId'";
			$rstUpdUsr = mysql_query($sqlUpdUsr) or die(mysql_error());
			if($rstUpdUsr) { 
				$msg = "Your tokenID is successfully set.";
			}else{
				$msg = "Your tokenID is not set please try again!";
			}
		}	
	if($_REQUEST['comm_token_id']!=1)
	{
		$userId = $_SESSION['user_id_sess'];	
		$usrObj = new member_management;
		$rand = rand(100000, 10000000);		
	
		$pipeline = new Amazon_FPS_CBUIRecipientTokenPipeline(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY);
			
			if($_SESSION['user_type_sess']!='5')
			{
				$pipeline->setMandatoryParameters("swapen".rand(),  
						//H_ROOT."index.php?comm_token_id=1", "0", "0.0", "True");
						  H_ROOT."index.php?comm_token_id=1", "0", "3.0", "True");
			}	
			else
			{
				$pipeline->setMandatoryParameters("swapen".rand(),  
						//H_ROOT."index.php?comm_token_id=1", "0", "0.0", "True");
						  H_ROOT."index.php?comm_token_id=1", "0", "1.1", "True");
			}	  				
			$pipeline->addParameter("paymentMethod", "CC");
			$re_URL = $pipeline->getUrl();
			header("location:".$re_URL);
	}
	else
	{
		mysql_query("update tbl_users set set_api='Yes' where user_id='".$_SESSION['user_id_sess']."'") or die(mysql_error());
		if($_SESSION['user_type_sess']!='5')
		{
			//header("location:index.php?sell&by=own");
			//4:16PM 28/05/2011
			if($_SESSION['user_type_sess']=='2' || $_SESSION['user_type_sess']=='4') {
				$_SESSION['pass_amazon_land']=1; 
				header("location:index.php?sell&by=seller");
				} 
			else header("location:index.php?sell&by=own");
		}
		else
		{
		   header("location:index.php?import=1");
		}
		 
	}
	 
?>
